package PUSHSendIntegrator;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import HTTPSendIntegrator.MmsMessageException;
import HTTPSendIntegrator.MmsPart;

public class PUSHMmsMessage {
	
	public static final String MMS_READ_STATUS = "X-Mms-Read-Status:";
	private String mmsReadStatus;
	
	public static final String MMS_MESSAGE_SIZE = "X-Mms-Message-Size:";
	private String mmsMessageSize;
	
	protected static final String NL = "\r\n";

	public static final String MMS_REPRT_ALLOWED = "X-Mms-Report-Allowed:";
	private String mmsReportAllowed;
	
	public static final String MMS_STATUS = "X-Mms-Status:";
	private String mmsStatus;

	public static final String MMS_READ_REPORT = "X-Mms-Read-Report:";
	private String mmsReadReport;

	/*
	 * =========================================================================
	 * Header Name Constants
	 * =========================================================================
	 */
	public static final String MMS_MESSAGE_TYPE = "X-Mms-Message-Type:";
	public static final String MMS_TRANSACTION_ID = "X-Mms-Transaction-ID:";
	public static final String MMS_VERSION = "X-Mms-MMS-Version:";
	public static final String MMS_DATE = "Date:";
	public static final String MMS_FROM = "From:";
	public static final String MMS_TO = "To:";
	public static final String MMS_CC = "CC:";
	public static final String MMS_BCC = "BCC:";
	public static final String MMS_SUBJECT = "Subject:";
	public static final String MMS_CLASS = "X-Mms-Message-Class:";
	public static final String MMS_EXPIRY = "X-Mms-Expiry:";
	public static final String MMS_DELIVERY_TIME = "X-Mms-Delivery-Time:";
	public static final String MMS_DELIVERY_REPORT = "X-Mms-Delivery-Report:";
	public static final String MMS_READ_REPLY = "X-Mms-Read-Reply:";
	public static final String MMS_STORE = "X-Mms-Store:";

	public static final String MMS_CONTENT_TYPE = "Content-Type:";
	public static final String MMS_RESPONSE_STATUS = "X-Mms-Response-Status:";
	public static final String MMS_RESPONSE_TEXT = "X-Mms-Response-Text:";
	public static final String MMS_MESSAGE_ID = "Message-ID:";
	public static final String MMS_CONTENT_LOCATION_VALUE = "X-Mms-Content-Location:";
	
	/*
	 * =========================================================================
	 * Header Value Constants
	 * =========================================================================
	 */
	public static final String CHARSET_US_ASCII = "us-ascii";
	public static final String CHARSET_UTF8 = "utf-8";

	public static final String MMS_MESSAGE_TYPE_NOTI_IND = "m-notification-ind";
	public static final String MMS_MESSAGE_TYPE_DELIVERY_IND = "m-delivery-ind";
	public static final String MMS_MESSAGE_TYPE_READ_ORG = "m-read-orig-ind";

	public static final String MMS_VERSION_1 = "1.0";

	public static final String MMS_DELIVERY_REPORT_YES = "Yes";
	public static final String MMS_DELIVERY_REPORT_NO = "No";

	public static final String MMS_CLASS_PERSONAL = "Personal";
	public static final String MMS_CLASS_ADVERTISEMENT = "Advertisement";
	public static final String MMS_CLASS_INFORMATIONAL = "Informational";
	public static final String MMS_CLASS_AUTO = "Auto";

	public static final String MMS_READ_REPLY_YES = "Yes";
	public static final String MMS_READ_REPLY_NO = "No";

	public static final String MMS_STORE_YES = "Yes";
	public static final String MMS_STORE_NO = "No";

	public static final String MMS_RESPONSE_STATUS_OK = "OK";
	public static final String MMS_RESPONSE_STATUS_ERROR_UNSPECIFIED = "Error-unspecified";
	public static final String MMS_RESPONSE_STATUS_ERROR_SERVICE_DENIED = "Error-service-denied";
	public static final String MMS_RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT = "Error-message-format-corrupt";
	public static final String MMS_RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED = "Error-sending-address-unresolved";
	public static final String MMS_RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND = "Error-message-not-found";
	public static final String MMS_RESPONSE_STATUS_ERROR_NETWORK_PROBLEM = "Error-network-problem";
	public static final String MMS_RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED = "Error-contant-not-accepted";
	public static final String MMS_RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE = "Error-unsupported-message";

	public static final String MMS_SENDER_VISIBILITY_HIDE = "Hide";
	public static final String MMS_SENDER_VISIBILITY_SHOW = "Show";

	public static final String MMS_ADDRESS_TYPE_MOBILE_NUMBER = "/TYPE=PLMN";
	public static final String MMS_ADDRESS_TYPE_MAIL = "";
	public static final String MMS_ADDRESS_TYPE_IPV4 = "/TYPE=IPV4";

	/*
	 * =========================================================================
	 * CONTENT TYPE CONSTANTS
	 * =========================================================================
	 */
	public static final String CTYPE_UNKNOWN = "*/*";
	public static final String CTYPE_TEXT = "text/*";
	public static final String CTYPE_TEXT_PLAIN = "text/plain";
	public static final String CTYPE_TEXT_HTML = "text/html";
	public static final String CTYPE_TEXT_WML = "text/wnd.vap.wml";
	public static final String CTYPE_IMAGE = "image/*";
	public static final String CTYPE_IMAGE_JPEG = "image/jpeg";
	public static final String CTYPE_IMAGE_GIF = "image/gif";
	public static final String CTYPE_IMAGE_PNG = "image/png";
	public static final String CTYPE_MULTIPART = "multipart/*";
	public static final String CTYPE_MULTIPART_MIXED = "multipart/mixed";
	public static final String CTYPE_APPLICATION_MULTIPART_MIXED = "application/vnd.wap.multipart.mixed";
	public static final String CTYPE_APPLICATION_MULTIPART_RELATED = "application/vnd.wap.multipart.related";

	/*
	 * =========================================================================
	 * CLASS VARIABLES
	 * =========================================================================
	 */
	protected String mmsMessageType;
	protected String mmsTransactionId;
	protected String mmsVersion;
	protected String mmsDate;
	protected String mmsFrom;
	protected ArrayList<String> mmsTo;
	protected ArrayList<String> mmsCC;
	protected ArrayList<String> mmsBCC;
	
	protected String readMmsTo;
	protected String readFrom;
	
	private String mmsSubject;
	private String mmsClass;

	private String mmsExpiryTime;

	private Date mmsDeliveryTime;

	private Boolean mmsDeliveryReport;
	private Boolean mmsReadReply;
	protected Boolean mmsStore;

	private String mmsContentType;
	private String mmsResponseStatus;
	private String mmsResponseText;
	protected String mmsMessageID;
	private String mmsContentLocationValue;
	protected ArrayList<MmsPart> mmsParts;

	/*
	 * =========================================================================
	 * CONSTRUCTORS
	 * =========================================================================
	 */
	/** Creates an MmsMessage object. */
	public PUSHMmsMessage() {
		this.mmsTo = new ArrayList<String>();
		this.mmsCC = new ArrayList<String>();
		this.mmsBCC = new ArrayList<String>();
		this.mmsParts = new ArrayList<MmsPart>();
	}

	/*
	 * =========================================================================
	 * METHODS
	 * =========================================================================
	 */
	public void setStatus(String mmsStatus){
		this.mmsStatus = mmsStatus;
	}
	public String getStatus(){
		return mmsStatus;
	}
	public boolean isStatusSet(){
		return this.mmsStatus != null;
	}
	
	/** Sets the transaction id. */
	public void setReadMmsTo(String readMmsTo) {
		this.readMmsTo = readMmsTo;
	}

	/** Checks if the transaction identifier is set */
	public boolean isReadMmsTo() {
		return readMmsTo != null;
	}
	
	public String getReadMmsTo(){
		return this.readMmsTo;
	}
	
	/** Sets the transaction id. */
	public void setReadFrom(String readFrom) {
		this.readFrom = readFrom;
	}

	/** Checks if the transaction identifier is set */
	public boolean isReadFrom() {
		return readFrom != null;
	}
	
	public String getReadFrom(){
		return this.readFrom;
	}

	/** Sets the transaction id. */
	public void setReadStatus(String mmsReadStatus) {
		this.mmsReadStatus = mmsReadStatus;
	}

	/** Checks if the transaction identifier is set */
	public boolean isReadStatusSet() {
		return mmsReadStatus != null;
	}
	
	public String getReadStatus(){
		return this.mmsReadStatus;
	}

	
	/** Sets the transaction id. */
	public void setMessageSize(String mmsMessageSize) {
		this.mmsMessageSize = mmsMessageSize;
	}

	/** Checks if the transaction identifier is set */
	public boolean isMessageSizeSet() {
		return mmsMessageSize != null;
	}
	
	public String getMessageSize(){
		return this.mmsMessageSize;
	}
	
	public String getFrom(){
		return mmsFrom;
	}
	public boolean getStore(){
		return mmsStore;
	}
	/**
	 * Sets the MMS message type.<br>
	 * 
	 * Supported types:
	 * <ol>
	 * <li>{@link PUSHMmsMessage#MMS_MESSAGE_TYPE_SEND_REQUEST}</li>
	 * <li>{@link PUSHMmsMessage#MMS_MESSAGE_TYPE_SEND_CONF}</li>
	 * </ol>
	 * 
	 * @param type
	 *            type of the message
	 * @throws MmsMessageException
	 *             message type not supported
	 */
	
	public void setMessageType(String type) throws MmsMessageException {
		if (type.equals(MMS_MESSAGE_TYPE_NOTI_IND))
			this.mmsMessageType = type;
		else if (type.equals(MMS_MESSAGE_TYPE_DELIVERY_IND))
			this.mmsMessageType = type;
		else if (type.equals(MMS_MESSAGE_TYPE_READ_ORG))
			this.mmsMessageType = type;
		else
			throw new MmsMessageException("Message type \"" + type
					+ "\" not supported.");
	}

	/** Checks if the message type is specified. */
	public boolean isMessageTypeSet() {
		return mmsMessageType != null;
	}

	/** Sets the transaction id. */
	public void setTransactionID(String id) {
		this.mmsTransactionId = id;
	}

	/** Checks if the transaction identifier is set */
	public boolean isTransactionIDSet() {
		return mmsTransactionId != null;
	}

	/** Sets the version of the MMS message.<br> */
	public void setVersion(String version) throws MmsMessageException {
		if (version.equals(MMS_VERSION_1))
			this.mmsVersion = version;
		else
			throw new MmsMessageException("Message version \"" + version
					+ "\" not supported.");
	}

	/** Checks if the version is present. */
	public boolean isVersionSet() {
		return mmsVersion != null;
	}

	/** Sets the message date. */
	public void setMessageDate(String d) {
		this.mmsDate = d;
	}

	/**
	 * Checks if the message date is present.
	 * 
	 * @return true if present, false otherwise
	 */
	public boolean isMessageDateSet() {
		return mmsDate != null;
	}

	/**
	 * Set the message sender.<br>
	 * 
	 * Supported values for <i>addressType</i>
	 * <ol>
	 * <li>{@link #MMS_ADDRESS_TYPE_IPV4}</li>
	 * <li>{@link #MMS_ADDRESS_TYPE_MAIL}</li>
	 * <li>{@link #MMS_ADDRESS_TYPE_MOBILE_NUMBER}</li>
	 * </ol>
	 * 
	 * @param sender
	 *            sender address
	 * @param addressType
	 *            address type
	 * @throws MmsMessageException
	 *             address type not supported
	 */
	public void setMessageSender(String sender, String addressType)
			throws MmsMessageException {
		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MAIL)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER))
			throw new MmsMessageException("Address type \"" + addressType
					+ "\" not supported.");
		this.mmsFrom = sender + addressType;
	}

	/** Checks if the message sender is specified. */
	public boolean isMessageSenderSet() {
		return mmsFrom != null;
	}

	/** Adds a message receiver. */
	public void addMessageReceiver(String receiver, String addressType)
			throws MmsMessageException {
		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MAIL)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER))
			throw new MmsMessageException("Address type \"" + addressType
					+ "\" not supported.");
		this.mmsTo.add(receiver + addressType);
	}

	/**
	 * Checks if there is at least one receiver.
	 * 
	 * @return true if a receiver is present
	 */
	public boolean isMessageReceiverSet() {
		return mmsTo.size() > 0;
	}

	/**
	 * Returns the receivers for this MMS message.
	 * 
	 * @return receivers list
	 */
	public List<String> getMessageReceivers() {
		return mmsTo;
	}

	/**
	 * Adds a message CC.
	 * 
	 * @param receiver
	 *            CC address
	 * @param addressType
	 *            address type
	 * @throws MmsMessageException
	 *             address type not supported
	 * @see #setMessageSender(String, String)
	 */
	public void addMessageCC(String receiver, String addressType)
			throws MmsMessageException {
		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MAIL)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER))
			throw new MmsMessageException("Address type \"" + addressType
					+ "\" not supported.");
		this.mmsCC.add(receiver + addressType);
	}

	/**
	 * Checks if there is at least one message CC.
	 * 
	 * @return true if one or more CC are present
	 */
	public boolean isMessageCCSet() {
		return mmsCC.size() > 0;
	}

	/**
	 * Return the CCs list.
	 * 
	 * @return CC list
	 */
	public List<String> getMessageCC() {
		return mmsCC;
	}

	/**
	 * Adds a message BCC
	 * 
	 * @param receiver
	 *            BCC address
	 * @param addressType
	 *            address type
	 * @throws MmsMessageException
	 *             address type not supported
	 * @see #setMessageSender(String, String)
	 */
	public void addMessaceBCC(String receiver, String addressType)
			throws MmsMessageException {
		if (!addressType.equals(MMS_ADDRESS_TYPE_IPV4)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MAIL)
				&& !addressType.equals(MMS_ADDRESS_TYPE_MOBILE_NUMBER))
			throw new MmsMessageException("Address type \"" + addressType
					+ "\" not supported.");
		this.mmsBCC.add(receiver + addressType);
	}

	/**
	 * Checks if at least one BCC is present.
	 * 
	 * @return true if present
	 */
	public boolean isMessageBCCSet() {
		return mmsBCC.size() > 0;
	}

	/**
	 * Return the BCCs list
	 * 
	 * @return BCC list
	 */
	public List<String> getMessageBCC() {
		return mmsBCC;
	}

	/**
	 * Sets the message subject
	 * 
	 * @param subject
	 */
	public void setMessageSubject(String subject) {
		this.mmsSubject = subject;
	}

	/**
	 * Checks if the subject is present.
	 * 
	 * @return true if present
	 */
	public boolean isMessageSubjectSet() {
		return mmsSubject != null;
	}

	/**
	 * Sets the message class.<br>
	 * 
	 * Supported class:
	 * <ol>
	 * <li>{@link #MMS_CLASS_AUTO}</li>
	 * <li>{@link #MMS_CLASS_PERSONAL}</li>
	 * <li>{@link #MMS_CLASS_INFORMATIONAL}</li>
	 * <li>{@link #MMS_CLASS_ADVERTISEMENT}</li>
	 * </ol>
	 * 
	 * @param messageClass
	 *            message class
	 * @throws MmsMessageException
	 *             the message class is not supported
	 */
	public void setMessageClass(String messageClass) throws MmsMessageException {
		if (!messageClass.equals(MMS_CLASS_AUTO)
				&& !messageClass.equals(MMS_CLASS_PERSONAL)
				&& !messageClass.equals(MMS_CLASS_INFORMATIONAL)
				&& !messageClass.equals(MMS_CLASS_ADVERTISEMENT))
			throw new MmsMessageException("Message class \"" + messageClass
					+ "\" not supported");
		this.mmsClass = messageClass;
	}

	/**
	 * Checks if the message class is present.
	 * 
	 * @return true if present
	 */
	public boolean isMessageClassSet() {
		return mmsClass != null;
	}

	/**
	 * Sets the message expiry time.<br>
	 * 
	 * If the <i>absolute</i> parameter is true, then <i>time</i> is considered
	 * the exact date of expire for the mms message. Otherwise <i>time</i> will
	 * be added to the message date to calculate the exact expire date.
	 * 
	 * @param string
	 *            Time value
	 * @param absolute
	 *            Specifies if the time is relative or absolute
	 */
	public void setMessageExpiryTime(String string) {
		this.mmsExpiryTime = string;
	}

	/**
	 * Checks if the expiry time is specified.
	 * 
	 * @return true if present
	 */
	public boolean isMessageExpiryTimeSet() {
		return mmsExpiryTime != null;
	}

	/**
	 * Sets the message delivery time.
	 * 
	 * @param time
	 *            time value
	 * @param absolute
	 *            specifies if the time is relative or absolute
	 * @see #setMessageExpiryTime(Date, boolean)
	 */
	public void setMessageDeliveryTime(Date time) {
		this.mmsDeliveryTime = time;
	}

	/**
	 * Checks if the delivery time is present.
	 * 
	 * @return true if present
	 */
	public boolean isMessageDeliveryTimeSet() {
		return mmsDeliveryTime != null;
	}

	/**
	 * Enables/disables the message delivery report.
	 * 
	 * @param enabled
	 *            whether to enable the message delivery report
	 */
	public void setDeliveryReport(boolean enabled) {
		this.mmsDeliveryReport = new Boolean(enabled);
	}

	/**
	 * Enables/disables the message read reply.
	 * 
	 * @param enabled
	 *            whether to enable the message read reply
	 */
	public void setReadReply(boolean enabled) {
		this.mmsReadReply = new Boolean(enabled);
	}

	/**
	 * Enables/disables the message store.
	 * 
	 * @param enabled
	 *            whether to enable the message read reply
	 */
	public void setStore(boolean enabled) {
		this.mmsStore = new Boolean(enabled);
	}

	/**
	 * Set the response status.<br>
	 * 
	 * Supported responses:
	 * <ol>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_NETWORK_PROBLEM}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_SERVICE_DENIED}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_UNSPECIFIED}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE}</li>
	 * <li>{@link #MMS_RESPONSE_STATUS_OK}</li>
	 * </ol>
	 * 
	 * @param status
	 *            response status
	 * @throws MmsMessageException
	 *             status not supported
	 */
	public void setResponseStatus(String status) throws MmsMessageException {
		if (!status.equals(MMS_RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED)
				&& !status
						.equals(MMS_RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT)
				&& !status.equals(MMS_RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND)
				&& !status.equals(MMS_RESPONSE_STATUS_ERROR_NETWORK_PROBLEM)
				&& !status
						.equals(MMS_RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED)
				&& !status.equals(MMS_RESPONSE_STATUS_ERROR_SERVICE_DENIED)
				&& !status.equals(MMS_RESPONSE_STATUS_ERROR_UNSPECIFIED)
				&& !status
						.equals(MMS_RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE)
				&& !status.equals(MMS_RESPONSE_STATUS_OK))
			throw new MmsMessageException("Status \"" + status
					+ "\" not supported");
		this.mmsResponseStatus = status;
	}

	/**
	 * Checks if the response status is present.
	 * 
	 * @return true if present
	 */
	public boolean isResponseStatusSet() {
		return mmsResponseStatus != null;
	}

	/**
	 * Sets the response text.
	 * 
	 * @param text
	 *            response
	 */
	public void setResponseText(String text) {
		this.mmsResponseText = text;
	}

	/**
	 * Checks if the response text is present.
	 * 
	 * @return true if present
	 */
	public boolean isResonseTextSet() {
		return mmsResponseText != null;
	}

	public boolean isDeliveryReportSet() {
		return this.mmsDeliveryReport != null;
	}

	public boolean isReadReplySet() {
		return this.mmsReadReply != null;
	}


	//Sets and  Checks if the message identifier is present.
	public void setMessageID(String id) {
		this.mmsMessageID = id;
	}
	public boolean isMessageIDSet() {
		return mmsMessageID != null;
	}

	//Sets and Checks if the message identifier is present.
	public void setContentLocationValue(String mmsContentLocationValue){
		this.mmsContentLocationValue = mmsContentLocationValue;
	}
	public boolean isContentLocationValue() {
		return mmsContentLocationValue != null;
	}
	public String getContentLocationValue() {
		return this.mmsContentLocationValue;
	}
	
	/**
	 * Sets the content type for the message.<br>
	 * 
	 * Supported content types:
	 * <ol>
	 * <li>{@link #CTYPE_APPLICATION_MULTIPART_MIXED}</li>
	 * <li>{@link #CTYPE_APPLICATION_MULTIPART_RELATED}</li>
	 * <li>{@link #CTYPE_IMAGE}</li>
	 * <li>{@link #CTYPE_IMAGE_GIF}</li>
	 * <li>{@link #CTYPE_IMAGE_JPEG}</li>
	 * <li>{@link #CTYPE_IMAGE_PNG}</li>
	 * <li>{@link #CTYPE_IMAGE_TIFF}</li>
	 * <li>{@link #CTYPE_IMAGE_VND_WAP_WBMP}</li>
	 * <li>{@link #CTYPE_MULTIPART}</li>
	 * <li>{@link #CTYPE_MULTIPART_MIXED}</li>
	 * <li>{@link #CTYPE_TEXT}</li>
	 * <li>{@link #CTYPE_TEXT_HTML}</li>
	 * <li>{@link #CTYPE_TEXT_PLAIN}</li>
	 * <li>{@link #CTYPE_TEXT_WML}</li>
	 * <li>{@link #CTYPE_UNKNOWN}</li>
	 * </ol>
	 * 
	 * @param type
	 *            content type
	 */
	public void setMessageContentType(String type) {
		this.mmsContentType = type;
	}

	/**
	 * Chekcs if the message content type is present.
	 * 
	 * @return true if present
	 */
	public boolean isMessageContentTypeSet() {
		return mmsContentType != null;
	}

	/**
	 * Add a part to the MMS message.<br>
	 * Checks if the content type of the message is compatible with the content
	 * type of the part.
	 * 
	 * @param part
	 *            part to add to the message
	 * @throws MmsMessageException
	 *             the part is not compatible with the message
	 */
	public void addPart(MmsPart part) throws MmsMessageException {
		if (mmsContentType.equals(CTYPE_MULTIPART)
				|| mmsContentType.equals(CTYPE_MULTIPART_MIXED)
				|| mmsContentType.equals(CTYPE_APPLICATION_MULTIPART_MIXED)
				||
				// Multipart related not yet supported
				mmsContentType.equals(CTYPE_APPLICATION_MULTIPART_RELATED)
				|| mmsContentType.equals(CTYPE_UNKNOWN))
			mmsParts.add(part);
		else if (mmsParts.size() == 0)
			mmsParts.add(part);
		else
			throw new MmsMessageException(
					"Only one part admitted in a non Multipart message");
	}

	/**
	 * Return the number of parts in the message.
	 * 
	 * @return parts number
	 */
	public int getPartsNumber() {
		return mmsParts.size();
	}

	/**
	 * Returns the mms parts in the message.
	 * 
	 * @return mms parts
	 */
	public List<MmsPart> getParts() {
		return mmsParts;
	}

	/**
	 * Returns the ith part or null if <i>i</i> is greater then parts number.
	 * 
	 * @param i
	 *            part number desidered
	 * @return ith part number
	 */
	public MmsPart getPart(int i) {
		try {
			return mmsParts.get(i);
		} catch (IndexOutOfBoundsException e) {
			return null;
		}
	}

	/**
	 * Returns the message type.
	 * 
	 * @return message type
	 */
	public String getMessageType() {
		return this.mmsMessageType;
	}

	/**
	 * Returns the transaction id.
	 * 
	 * @return transaction id
	 */
	public String getTransactionID() {
		return this.mmsTransactionId;
	}

	/**
	 * Return the version of the MMS Protocol.
	 * 
	 * @return version of MMS
	 */
	public String getVersion() {
		return this.mmsVersion;
	}

	/**
	 * Returns the date of the message.
	 * 
	 * @return message's date
	 */
	public String getMessageDate() {
		return this.mmsDate;
	}
	/**
	 * Return the message sender.
	 * 
	 * @return sender
	 */
	public String getMessageSender() {
		return this.mmsFrom;
	}

	/**
	 * Return the message subject.
	 * 
	 * @return message subject
	 */
	public String getMessageSubject() {
		return this.mmsSubject;
	}

	/**
	 * Returns the message class.
	 * 
	 * @return message class
	 */
	public String getMessageClass() {
		return this.mmsClass;
	}

	/**
	 * Returns the message expiry time.
	 * 
	 * @return expiry time
	 */
	public String getMessageExpiryTime() {
		return this.mmsExpiryTime;
	}

	/**
	 * Returns the delivery time of the message.
	 * 
	 * @return delivery time
	 */
	public Date getMessageDeliveryTime() {
		return this.mmsDeliveryTime;
	}

	/**
	 * Checks whether the delivery report is enabled
	 * 
	 * @return true if enabled
	 */
	public boolean isDeliveryReportEnabled() {
		return this.mmsDeliveryReport;
	}

	/**
	 * Checks whether the read reply is enabled
	 * 
	 * @return true if enabled
	 */
	public boolean isReadReplyEnabled() {
		return this.mmsReadReply;
	}

	public boolean isStoreEnabled() {
		return this.mmsStore;
	}

	/**
	 * Returns the response status.
	 * 
	 * @return response status
	 */
	public String getResponseStatus() {
		return this.mmsResponseStatus;
	}

	/**
	 * Returns the response text
	 * 
	 * @return response text
	 */
	public String getResponseText() {
		return this.mmsResponseText;
	}

	/**
	 * Returns the message identifier
	 * 
	 * @return message identifier
	 */
	public String getMessageID() {
		return this.mmsMessageID;
	}

	/**
	 * Returns the message content type.
	 * 
	 * @return message content type
	 */
	public String getMessageContentType() {
		return this.mmsContentType;
	}

	/**
	 * Produce a string representation of the message easily readable by a
	 * human.
	 * 
	 * @return string representation of the message
	 */
	public String toString() {
		String mmsMessage = "";
		return mmsMessage;
	}
}
